package com.wpf.rounter2function.routers;

import com.wpf.rounter2function.handler.PersonHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.*;

@Configuration
public class HandlerRouter {

    @Bean
    RouterFunction<ServerResponse> personRouter(PersonHandler handler){

        return RouterFunctions.nest(
                RequestPredicates.path("/person"),
                RouterFunctions.route(RequestPredicates.GET("/getAll"),handler::queryAll)
                .andRoute(RequestPredicates.POST("/save").
                        and(RequestPredicates.accept(MediaType.APPLICATION_JSON_UTF8)),handler::save)
                .andRoute(RequestPredicates.DELETE("/delete/{id}"),handler::delete)
        );
    }
}
